Skip to content

smite-ir: Introduce affine state variables for strict state enforcement#97

Merged
morehouse merged 8 commits into
morehouse:masterfrom
Chand-ra:implicit_dependence
Jun 5, 2026
Merged

smite-ir: Introduce affine state variables for strict state enforcement#97
morehouse merged 8 commits into
morehouse:masterfrom
Chand-ra:implicit_dependence

Conversation

@Chand-ra

Copy link
Copy Markdown

This PR introduces affine (single-use) types to the IR to strictly enforce the Lightning Network state machine during fuzzing, in order to prevent timeout hangs caused by semantically invalid mutation sequences.

Solves issue #75, see it for more details.

@Chand-ra Chand-ra force-pushed the implicit_dependence branch 2 times, most recently from 531ca61 to 798752a Compare May 25, 2026 11:16
@Chand-ra Chand-ra mentioned this pull request May 27, 2026
9 tasks
Comment thread smite-ir/src/operation.rs Outdated
Comment thread smite-ir/src/builder.rs Outdated
Comment on lines +136 to +140
let candidate_to_resolve = chosen_candidate
.unwrap_or_else(|| candidates.last().unwrap())
.clone();
return self.resolve_candidate(candidate_to_resolve);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed here, this is an anti-pattern and we should modify the function's signature to return an Option<usize> instead of intentionally generating an invalid instruction.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to panic instead, because that's in-line with the current behavior. SpliceMutator will require this behavior to change as a whole, so I'll modify it if and when we need it instead of front-loading the complexity in this PR.

Comment thread smite-ir/src/variable.rs Outdated
Comment thread smite-ir/src/variable.rs Outdated
Comment thread smite-ir/src/operation.rs
Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-ir/src/operation.rs Outdated
Comment thread smite-ir/src/program.rs Outdated
Comment thread smite-ir/src/operation.rs Outdated
Comment thread smite-scenarios/src/executor.rs
Comment thread smite-ir-mutator/src/lib.rs Outdated
@Chand-ra Chand-ra force-pushed the implicit_dependence branch 2 times, most recently from 34528b0 to 18143e2 Compare June 1, 2026 06:43
@Chand-ra

Chand-ra commented Jun 1, 2026

Copy link
Copy Markdown
Author

Rebased on top of the latest master to resolve merge conflicts.

Comment thread smite-ir/src/builder.rs
Comment thread smite-ir/src/mutators/input_swap.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-ir/src/operation.rs
@Chand-ra Chand-ra force-pushed the implicit_dependence branch 4 times, most recently from 825f42b to 982d207 Compare June 2, 2026 07:04
@Chand-ra

Chand-ra commented Jun 2, 2026

Copy link
Copy Markdown
Author

Had to rebase again to solve a merge conflict.

Comment thread smite-ir/src/builder.rs
Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-ir/src/builder.rs
Comment thread smite-ir/src/mutators/input_swap.rs
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
@Chand-ra Chand-ra force-pushed the implicit_dependence branch from 982d207 to 5d3fd3c Compare June 3, 2026 07:16

@morehouse morehouse left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks correct to me now. All my remaining comments are nits related to style or missing tests.

Also the commit message for d7f0788 is slightly out-of-date and the first bullet point should be updated to:

- Add `SendOpenChannel` operation: Consumes a composed `OpenChannelMessage`
  and outputs a `SentOpenChannel` affine variable.

Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-ir/src/builder.rs
Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-ir/src/operation.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-ir/src/tests.rs
Comment thread smite-scenarios/src/executor.rs Outdated
Comment thread smite-scenarios/src/executor.rs Outdated
@Chand-ra Chand-ra force-pushed the implicit_dependence branch 4 times, most recently from cda5521 to 9cf3cc8 Compare June 4, 2026 05:41
@Chand-ra

Chand-ra commented Jun 4, 2026

Copy link
Copy Markdown
Author

Had to rebase (yet again) to resolve a merge conflict.

@morehouse morehouse left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message for 9cfec5c still says a Message is consumed when in fact it is an OpenChannelMessage.

Comment thread smite-ir/src/tests.rs Outdated
Comment thread smite-ir/src/builder.rs
Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-ir/src/builder.rs Outdated
Comment thread smite-ir/src/tests.rs
@Chand-ra Chand-ra force-pushed the implicit_dependence branch 4 times, most recently from 9707aaf to 74e6a8c Compare June 4, 2026 16:33
Comment thread smite-ir/src/builder.rs
@Chand-ra Chand-ra force-pushed the implicit_dependence branch from 74e6a8c to 466fd5f Compare June 5, 2026 04:51
Chandra Pratap added 8 commits June 5, 2026 04:52
Add `SentOpenChannel` to the `Variable` and `VariableType` enums.
Unlike standard data variables which can be referenced infinitely,
this new type is designed to be "affine" (single-use).

Affine variables represent strict topological locks in the LN
state machine  (e.g., `SentOpenChannel` ensures a channel is
actively pending before allowing a `RecvAcceptChannel`).
Update `pick_variable` with a dedicated branch for affine types.
Unlike data variables which use a probabilistic 75/15/10 strategy,
affine types use deterministic tip-tracking.
Update `Program::validate()` to enforce the single-use nature
of affine state variables, preventing mutators from generating
impossible state-machine sequences.

Add a validation rule:

An affine variable cannot be consumed as an input more than once.
This prevents mutators from reusing old state variables to bypass
protocol ordering.
Affine variables carry no data and act purely as state tokens,
so swapping them yields no practical fuzzing value.

While at it, add a test to verify the change.
Introduce a dedicated `OpenChannelMessage` variable, separating
it from the generic `Message` type. This strongly types the output
of `BuildOpenChannel`, and is used as an input to `SendOpenChannel`
in a subsequent commit.

This prevents `InputSwapMutator` from swapping it with a different
message type, possibly causing a timeout.
Introduce the strict topological link for channel initialization.

- Add `SendOpenChannel` operation: Consumes a composed
  `OpenChannelMessage` and outputs a `SentOpenChannel` affine
  variable.

- Modify `RecvAcceptChannel`: Now requires `SentOpenChannel` as an
  input, enforcing that the fuzzer cannot wait for an
  `accept_channel` unless it actually opened a channel first.

- Update unit tests to accommodate the new input requirements for
  `RecvAcceptChannel`.
Update `OpenChannelGenerator` to utilize the newly introduced
strict topological operations:

1. Replace `SendMessage` with `SendOpenChannel`, which consumes
   the `Message` payload and outputs a `SentOpenChannel`.

2. Update `RecvAcceptChannel` to consume the `SentOpenChannel`.

3. Update tests to accommodate the non-void output of
   `SendOpenChannel`.
Add tests to verify the data-flow rules introduced for
state tracking.
@Chand-ra Chand-ra force-pushed the implicit_dependence branch from 466fd5f to a6032db Compare June 5, 2026 04:52

@morehouse morehouse left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Also did a 15 minute smoke test fuzzing LDK, and no issues.

@morehouse morehouse merged commit fe0a679 into morehouse:master Jun 5, 2026
5 checks passed
@Chand-ra Chand-ra deleted the implicit_dependence branch June 6, 2026 04:21
Comment thread smite-ir/src/operation.rs
Self::LoadChannelType(v) => write!(f, "LoadChannelType({v})"),
Self::LoadTargetPubkeyFromContext => write!(f, "LoadTargetPubkeyFromContext()"),
Self::LoadChainHashFromContext => write!(f, "LoadChainHashFromContext()"),
Self::RecvAcceptChannel => write!(f, "RecvAcceptChannel()"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that RecvAcceptChannel takes SentOpenChannel as input, the empty parens should be removed here and the corresponding tests, comments etc should also be updated accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants